package cn.richard.demo.drools.core;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class DroolsReloadFlagConfigListener extends AbsNacosConfigPropertiesListener{
	@Autowired
	private AppDroolsConfigPropertiesBean appDroolsConfigPropertiesBean;
	
	@Autowired
	private KieUtilService kieUtilService;
	
	@Override
	protected String getDataId() {
		return appDroolsConfigPropertiesBean.getReloadTriggerFile();
	}

	@Override
	protected String getGroup() {
		return super.DEFAULT_GROUP;
	}

	@Override
	protected String getNamespace() {
		return super.DEFAULT_NAMESPACE;
	}

	@Override
	protected void onContentChanged(String newContent) {
		log.info("监听到目标Nacos文件改动，准备Drools规则重载！");
		kieUtilService.reload();
	}

}
